home *** CD-ROM | disk | FTP | other *** search
AMOS Source Code | 1978-10-10 | 8.7 KB | 307 lines |
- '--------------------------------------------------------------------------
- ' SoundTracker Module converter
- ' By Fran�ois Lionet
- '
- ' Converts SoundTracker (1.0 to 2.4) modules to AMOS Music bank
- '--------------------------------------------------------------------------
- ' This music converter has been successfully tested with
- ' 1.0, 2.1, 2.3, 2.4 modules. If you find a version that does not
- ' work, please send it to Mandarin and we'll adapt it to work. We'll
- ' release any new versions onto the public domain as soon as they are
- ' complete. The AMOS Club is the best place to keep up-to-date with such
- ' developments.
- ' SoundTracker modules do not have an identification number describing
- ' which version they are. There is absolutely NO WAY for us to detect
- ' if the versions match. Therefore, you should be sure about the
- ' version you type in, as it WILL crash the Amiga!!!
- '--------------------------------------------------------------------------
- ' Version 1.1 of AMOS music player does not support:
- '
- ' Arpeggiato. This converter simply skips it. It also skips the
- ' "position jump" soundtracker instruction. If you hear a bell sound during
- ' conversion, the converter has just skipped past one of these labels.
- '
- ' Version 1.2 will support this and much more (like synthetic instruments for
- ' example...) C'est promis jur�! Regards from the army! Francois!
- '--------------------------------------------------------------------------
- ' Opens a very small screen to save memory
- Screen Open 0,640,48,2,Hires : Colour 1,$FFF
- '
- Global TST,AMAX,ABASE
- '
- IMAX=14 : Dim APAT(5)
- SONGDATA=4
- I$="Not named "
- I_END=$8000
- I_SLUP=$8100
- I_SLDOWN=$8200
- I_SVOL=$8300
- I_REP=$8500
- I_LEDM=$8600
- I_LEDA=$8700
- I_TEMPO=$8800
- I_INST=$8900
- '
- AGAIN:
- ST$=Fsel$("","","Please enter module to convert")
- If ST$="" Then Default : End
- Open In 1,ST$ : BMAX=Lof(1) : Close
- Erase 10 : Reserve As Work 10,BMAX
- Bload ST$,Start(10)
- '---> What version of Soundtracker?
- Repeat
- Input "Please input the soundtracker version number (x.x) : ";V$
- V$=Left$(V$,1)
- Until(V$="1") or(V$="2")
- If V$="1"
- OF_MUSIC=600
- OF_PATTERN=472
- OF_NUMBER=470
- Else
- OF_MUSIC=$438
- OF_PATTERN=$3B8
- OF_NUMBER=$3B6
- End If
- '---> Gets size of instruments and song
- TST=-1 : Gosub I_CONV
- TST=-1 : Gosub S_CONV
- '---> Converts patterns
- LWORK=(((BMAX-LINST-LSONG)*2)/3+1) and $FFFFFFFE
- N=0
- Repeat
- If N=0
- Print "Converting song..."
- Else
- Print : Print "One more try: my buffer estimation was too small!"
- End If
- Gosub P_CONV : Print
- LWORK=LWORK+4000
- Inc N
- Until LPATTERN
- '---> Converts song
- Print : Print "Converting song..."
- TST=0 : Gosub S_CONV
- '---> Converts instruments
- Print : Print "Converting instruments..."
- TST=0 : Gosub I_CONV
- ' Creates header
- AD=Start(10) : A$="AmBk" : Gosub 10100 : Doke AD,3 : Doke AD+2,0 : AD=AD+4
- TL=8+16+LINST+LSONG+LPATTERN : Loke AD,$80000000 or TL : AD=AD+4
- A$="Music " : Gosub 10100
- Loke AD,16 : Loke AD+4,16+LINST : Loke AD+8,16+LINST+LSONG : Loke AD+12,0 : AD=AD+16
- ' Copy instrument
- SAMCOPY[SCOPY,ECOPY,AD+NI*32+2+4]
- Copy Start(11),Start(11)+NI*32+2 To AD
- Loke AD+2+NI*32,0
- ' Copy Song
- Copy Start(12),Start(12)+LSONG To AD+LINST
- ' Copy Patterns
- Copy Start(13),Start(13)+LPATTERN To AD+LINST+LSONG
- '
- Clw : ABK$=Fsel$("*.abk","","Save as Amos Music Bank .abk") : If ABK$="" Then Goto AGAIN
- Print : Print "Saving AMOS music bank..."
- Bsave ABK$,Start(10) To AD+LINST+LSONG+LPATTERN
- ' Play the music!
- Clw : Centre "Loading the new bank to play it!"
- For N=10 To 13
- Erase N
- Next
- Load ABK$ : Volume 63 : Music 1
- Clw : Centre "Press a key to end..."
- Wait Key
- For V=63 To 0 Step -1
- Volume V
- Wait Vbl
- Next
- Erase 3
- Clw
- ' And now, happy structured people, a nice GOTO! Arghhh, kill him!
- Goto AGAIN
- '----------------------------------------------------------------------------
- ' Instrument conversion
- '----------------------------------------------------------------------------
- I_CONV:
- AD=Start(10)
- NPAT=0
- For A=AD+OF_PATTERN To AD+OF_PATTERN+127
- NPAT=Max(NPAT,Peek(A))
- Next A
- Inc NPAT : LMAX=NPAT*1024
- ADI=AD+LMAX+OF_MUSIC
- NI=1
- For A=AD+20 To AD+20+$1E*15 Step $1E
- If Deek(A+22) Then Inc NI
- Next
- Erase 11 : Reserve As Work 11,NI*32+2+4 : APOK=Start(11)
- AOFF=APOK : SDOKE[AOFF,NI] : AOFF=AOFF+2 : AINST=AOFF+NI*32
- INUL=AINST : SLOKE[AINST,0] : AINST=AINST+4 : SCOPY=ADI
- A=AD+20
- For N=1 To NI
- SLOKE[AOFF,AINST-APOK] : L=Deek(A+22) : SDOKE[AOFF+8,L]
- I2=Deek(A+26) : L2=Deek(A+28)
- If L2=1
- SLOKE[AOFF+4,INUL-APOK] : SDOKE[AOFF+10,2]
- Else
- SLOKE[AOFF+4,AINST-APOK+I2] : SDOKE[AOFF+10,L2]
- End If
- SDOKE[AOFF+12,Deek(A+24)]
- L=L*2 : ECOPY=ADI+L
- ADI=ADI+L : AINST=AINST+L
- For P=0 To 15 : SPOKE[AOFF+16+P,Peek(A+P)] : Next
- Add AOFF,32 : Add A,$1E
- Next
- If Btst(0,AINST) Then Inc AINST
- LINST=AINST-APOK
- Return
- '----------------------------------------------------------------------------
- ' Song conversion
- '----------------------------------------------------------------------------
- S_CONV:
- APOK=0
- If TST=0
- Erase 12 : Reserve As Work 12,LSONG : APOK=Start(12)
- Input "Please enter TEMPO value (1-100, default is 17):";T
- End If
- AD=Start(10) : AMU=APOK
- SDOKE[AMU,1] : Add AMU,2
- SLOKE[AMU,6] : Add AMU,4
- If T<=0 or T>100 Then T=17
- SDOKE[AMU+8,T]
- LLIST=Peek(AD+OF_NUMBER)
- LPAT=(LLIST+1)*2 : APAT=8+SONGDATA+16
- For N=0 To 3 : APAT(N)=AMU+APAT : SDOKE[AMU+N*2,APAT] : APAT=APAT+LPAT : Next N
- AMU=AMU+8+SONGDATA
- For A=0 To 15 : SPOKE[AMU+A,Peek(AD+A)] : Next : Add AMU,16
- AMU=AMU+LPAT*4
- For A=AD+OF_PATTERN To AD+OF_PATTERN+LLIST-1
- P=Peek(A)
- For V=0 To 3
- SDOKE[APAT(V),P] : APAT(V)=APAT(V)+2
- Next V
- Next A
- For V=0 To 3
- SDOKE[APAT(V),-2]
- Next V
- If Btst(0,AMU) Then Inc AMU
- LSONG=AMU-APOK
- Return
- '----------------------------------------------------------------------------
- ' Pattern conversion
- '----------------------------------------------------------------------------
- P_CONV:
- Erase 13 : Reserve As Work 13,LWORK : AMAX=Start(13)+LWORK-512 : Fill Start(13) To Start(13)+Length(13),0
- AD=Start(10) : AOFF=Start(13)
- Print "Number of different patterns:";NPAT
- APAT=AOFF+2+NPAT*8
- Doke AOFF,NPAT
- For NP=0 To NPAT-1 : PATMAX=64 : NBESS=0 : AAPAT=APAT
- O_AGAIN:
- For V=0 To 3 : Locate 0,Y Curs : Print "Computing pattern";NP;" - voice";V;
- AP=AD+OF_MUSIC+NP*1024
- Doke AOFF+2+NP*8+V*2,APAT-AOFF
- Gosub PP_CONV : If APAT>AMAX Then LPATTERN=0 : Return
- Next V
- If PATMAX<>64 and NBESS=0 Then NBESS=1 : APAT=AAPAT : Print : Goto O_AGAIN
- Next NP
- LPATTERN=APAT-Start(13)
- Return
- '
- PP_CONV:
- 3100 OI=-1 : VIT=1 : NN=0 : DEL=0 : ADN=0 : VOL=-1
- 3200 Inc NN : If NN>PATMAX Then 3250
- 3205 D1=Deek(AP+V*4) : D2=Deek(AP+V*4+2) : AP=AP+16
- 3210 I=(D2/$1000)+(D1/$1000)*16-1 : If I<0 Then If DEL+VIT<256 Then FLAG=1 : Gosub 3300 : DEL=DEL+VIT : Goto 3200 Else Stop
- 3215 Gosub 3400 : DEL=DEL+VIT
- 3220 If OI<>I Then Doke APAT,I_SVOL+63 : Add APAT,2 : VOL=63 : OI=I : Doke APAT,I_INST+I : Add APAT,2
- 3225 FLAG=0 : Gosub 3300
- 3230 Doke APAT,$7F00 : Doke APAT+2,D1 and $FFF : ADN=APAT : Add APAT,4
- 3235 Goto 3200
- '
- 3250 Gosub 3400
- 3255 Doke APAT,I_END : Add APAT,2 : Return
- '
- 3300 EFFECT=(D2 and $F00)/$100 : PRAM=D2 and $FF
- 3305 Goto 4000+EFFECT*50
- '
- 3400 If DEL=0 Then Return
- 3405 If ADN=0 and DEL<>0 Then Doke APAT,$7F00+DEL : Doke APAT+2,0 : Add APAT,4
- 3410 If ADN<>0 Then Poke ADN+1,DEL
- 3415 ADN=0 : DEL=0 : Return
- ' 0 No effect
- 4000 Return
- ' 1 Portamento UP
- 4050 If FLAG Then Gosub 3400
- 4055 Doke APAT,I_SLUP+PRAM : Add APAT,2 : Return
- ' 2 Portamento DOWN
- 4100 If FLAG Then Gosub 3400
- 4105 Doke APAT,I_SLDOWN+PRAM : Add APAT,2 : Return
- ' 3
- 4150 Return
- ' 4
- 4200 Return
- ' 5
- 4250 Return
- ' 6
- 4300 Return
- ' 7
- 4350 Return
- ' 8
- 4400 Return
- ' 9
- 4450 Return
- ' A Volume slide
- 4500 Bell : Return
- ' B Position jump
- 4550 Bell : Return
- ' C Set volume
- 4600 If FLAG Then Gosub 3400
- 4605 If VOL<>PRAM Then If OI>=0 Then Doke APAT,I_SVOL+PRAM : VOL=PRAM : Add APAT,2
- 4610 Return
- ' D Pattern break
- 4650 PATMAX=NN : Return
- ' E Led on / off
- 4700 If Btst(1,PRAM) Then Doke APAT,I_LEDM Else Doke APAT,I_LEDA
- 4705 Add APAT,2 : Return
- ' F Set tempo
- 4750 Doke APAT,I_TEMPO+(100/PRAM)
- 4755 Add APAT,2 : Return
- '
- 10000 For X=0 To Len(A$)-1
- 10005 SPOKE[A+X,Asc(Mid$(A$,X+1,1))]
- 10010 Next
- 10015 Return
- 10100 A=AD : Gosub 10000 : AD=AD+Len(A$) : Return
- '
- Procedure SPOKE[A,B]
- If TST=0
- Poke A,B
- End If
- End Proc
- '
- Procedure SDOKE[A,B]
- If TST=0
- Doke A,B
- End If
- End Proc
- '
- Procedure SLOKE[A,B]
- If TST=0
- Loke A,B
- End If
- End Proc
- '
- Procedure SAMCOPY[S,E,D]
- If TST=0
- If S mod 2=0 and E mod 2=0 and D mod 2=0
- Copy S,E To D
- Else
- Print "Slow Copying Sample"
- A=0
- While A+S<E
- Poke D+A,Peek(S+A)
- Inc A
- Wend
- Print "Done."
- End If
- End If
- End Proc